﻿using System;
using System.ServiceModel;
using VNet.VisiSuite.Common.Resource;
using VNet.VisiSuite.Common.VNetChannelFactory;
using VNet.VisiSuite.Service.Contact.Message.Base;
using VNet.VisiSuite.Service.Contact.Message.Item;
using VNet.VisiSuite.Service.Contact.Message.Security;
using VNet.VisiSuite.Service.Interface;

namespace VNet.VisiSuite.Service.Proxy
{
    public class VNetVisiSuiteSecurityContractClient : VNetChannelFactory<IVNetVisiSuiteSecurityService>, IVNetVisiSuiteSecurityService
    {
        public SignInResponse SignIn(SignInRequest request)
        {
            try
            {
                return ServiceCall(x => x.SignIn(request));
            }
            catch (EndpointNotFoundException) { return new SignInResponse { Success = false, Error = new ServiceError { Description = ErrorMessages.ServiceUrlInvalid } }; }
            catch (TimeoutException) { return new SignInResponse { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerTimeoutError } }; }
            catch (Exception) { return new SignInResponse { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerError } }; }
        }

        public SignOutResponse SignOut(SignOutRequest request)
        {
            try
            {
                return ServiceCall(x => x.SignOut(request));
            }
            catch (TimeoutException) { return new SignOutResponse { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerTimeoutError } }; }
            catch (Exception) { return new SignOutResponse { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerError } }; }
        }


        public GetDataResponse<LogoImageItem> DownloadLogoImage(GetDataRequest request)
        {
            try
            {
                return ServiceCall(x => x.DownloadLogoImage(request));
            }
            catch (EndpointNotFoundException) { return new GetDataResponse<LogoImageItem> { Success = false, Error = new ServiceError { Description = ErrorMessages.ServiceUrlInvalid } }; }
            catch (TimeoutException) { return new GetDataResponse<LogoImageItem> { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerTimeoutError } }; }
            catch (Exception) { return new GetDataResponse<LogoImageItem> { Success = false, Error = new ServiceError { Description = ErrorMessages.ServerError } }; }
       
        }
    }
}